package com.test.thread.consumer;

public class Q {
	private boolean valueSet = false;
	private int n;

	public synchronized int get() {
		if (!valueSet) {
			try {
				wait();
			} catch (InterruptedException e) {
				System.out.println("Q was Interrupted in get.");
			}
		}
		notify();
		System.out.println("Get: " + n);
		valueSet = false;
		return n;
	}

	public synchronized void put(int t) {
		if(valueSet){
			try {
				wait();
			} catch (InterruptedException e) {
				System.out.println("Q was Interrupted in put.");
			}
		}
		notify();
		valueSet=true;
		n = t;
		System.out.println("Put: " + t);
	}

}
